<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import="performReservation.SMMDBBean"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.Vector"%>
<%!
	Vector<String[]> vec = new Vector<String[]>();
	String sale_num = null;
	String type =null;
	String amount = null;
	Cookie cookies[] = null;
	String email = null;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Processing...</title>
</head>
<body>
	<%
		//auth
		cookies = request.getCookies();
		if(cookies!=null){
			for(int i = 0 ; i < cookies.length; i++){
				if(cookies[i].getName().equals("email")){
					email = cookies[i].getValue();
				}else 
				if(cookies[i].getName().equals("type")){
					type = cookies[i].getValue();
				}
			}
			if(type!=null&&type.equals("cus")){
				sale_num = request.getParameter("num");
				amount = request.getParameter("booking");
				
				if(!sale_num.equals("")&&!amount.equals("")){
					%><jsp:useBean id="order" scope="page" class="performReservation.Orders"/><%
					if(amount.equals("0")){
						//delete
						SMMDBBean pProcess = SMMDBBean.getInstance();
						order.setSalenum(Integer.parseInt(sale_num));
						boolean b = pProcess.deleteOrder(order);
						if(b){
							out.println("Your order has deleted");
							out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
						}else{
							out.println("something wrong with server!");
							out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
						}
						
					}else{
						order.setAmount(Integer.parseInt(amount));
						order.setCusemail(email);
						order.setSalenum(Integer.parseInt(sale_num));
						SMMDBBean pProcess = SMMDBBean.getInstance();
						int result = pProcess.bookingOrder(order);
						if(result==1){
							// order changed
							out.println("you order amount has changed to"+amount);
						}else if(result ==2){
							out.println("Sorry , We don't have so much ticket");
						}else if(result == 3){
							out.println("Congratulation, you ordered this performance");
							out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
						}else{
							out.println("something wrong with server!");
							out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
						}
					}
					}else{
					out.println("something wrong with server!");
					out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
				
				}
			}else{
				out.println("You have to login!");
				out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
			}
		}else{
			out.println("You have to login!");
			out.println("<a href=\"javascript:history.go(-1)\">Back</a>");
		}
	%>
	<%
		
	%>
</body>
</html>